exports.search_organization_course_comment = function (req, res) {

    var restfulParams = req.routeInfo.restfulParams;
    //最终结果
    var resultData = {};

    var skip  =  restfulParams.skip == undefined  ? 0 : restfulParams.skip;

    var limit =  restfulParams.limit == undefined ? config.publicConfig.LIMIT : restfulParams.limit;
    //任务流创建
    async.waterfall([
        //查询该用户的订单
        function (cb) {
            R.SEND_HTTP(
                req,
                {
                    url: CORE_APIConfig.coreAPI.search_order + "/o_pay_status/7/o_uid/" + restfulParams.oc_uid + "/skip/"+skip+"/limit/" + limit,
                    method: 'POST',
                    data: {
                        fields: ["o_aoc_id","o_type","o_activity_type"].join(",")
                    }
                },
                function (err, data) {
                    //判断是否有错误信息
                    if (err) {
                        return cb(err, data);
                    }

                    resultData.orderInfo = data.data;
                    cb();
                }
            );

        },
        //循环订单信息，并且根据type不同进不同的视图查询
        function(cb){
        //console.log("------------"+resultData.orderInfo+"----------------");

            var tasks = [];

            resultData.orderInfo.forEach(function (item, i) {
                ////console.log(item.fic_id);
                tasks.push(function (cb) {
                    if(item.o_type == 2){
                    R.SEND_HTTP(
                        req,
                        {
                            url: CORE_APIConfig.coreAPI.search_organization_course_comment + "/oc_uid/" + restfulParams.oc_uid +"/oc_cid/" + item.o_aoc_id,
                            method: 'POST',
                            data: {
                                fields: ["o_name", "o_logo","oc_create_time", "oc_title", "oc_content","oc_cid"].join(",")
                            }
                        },
                        function (err, data) {
                            if(err){
                                //console.log(err);
                            }
                            // var inviteData = data.data;
                            // //console.log(inviteData);
                            item.orderCommentInfo = data.data;
                            cb();
                        }
                    );
                    }
                    if(item.o_type == 0 ){
                         //console.log(item.o_type);
                        R.SEND_HTTP(
                            req,
                            {
                                url: CORE_APIConfig.coreAPI.search_organization_activity_comment + "/oac_fid/0/oac_is_reply/0/oac_uid/" + restfulParams.oc_uid +"/oac_oaid/" + item.o_aoc_id,
                                method: 'POST',
                                data: {
                                    fields: ["o_name ", "o_logo","oac_comment_time as oc_create_time", "oa_title as oc_title", "oac_content as oc_content","oac_oaid as oc_cid"].join(",")
                                }
                            },
                            function (err, data) {
                                if(err){
                                    //console.log(err);
                                }

                                item.orderCommentInfo = data.data;
                                cb();
                            }
                        );


                    }
                })
            });
            async.waterfall(tasks, cb);
        },




//===============================================//
//         function (cb) {
//             R.SEND_HTTP(
//                 req,
//                 {
//                     url: CORE_APIConfig.coreAPI.search_organization_course_comment + "/oc_uid/" + restfulParams.oc_uid ,
//                     method: 'POST',
//                     data: {
//                         fields: ["o_name", "o_logo","oc_create_time", "oc_title", "oc_content","oc_id"].join(",")
//                     }
//                 },
//                 function (err, data) {
//                     //判断是否有错误信息
//                     if (err) {
//                         return cb(err, data);
//                     }
//
//                     resultData.courseCommentInfo = data.data;
//                     cb();
//                 }
//             );
//
//         }
    ], function (err, result) {

        //返回最终拼接结果
        RES.response(res, true, resultData);

    });

}